<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>设置-个人信息</title>
	<link rel="icon" href="assets/img/favicon.ico">

	<link rel="stylesheet" type="text/css" href="/css/webbase.css" />
	<link rel="stylesheet" type="text/css" href="/css/pages-seckillOrder.css" />
</head>

<body>
<!-- 头部栏位 -->
<!--页面顶部-->
<div id="nav-bottom">
	<!--引入头部-->
	<div th:insert="/admin/common/head.html"></div>
</div>

<script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		$("#service").hover(function(){
			$(".service").show();
		},function(){
			$(".service").hide();
		});
		$("#shopcar").hover(function(){
			$("#shopcarlist").show();
		},function(){
			$("#shopcarlist").hide();
		});
		getAddress();
	})

	//查询
	function getAddress() {
		$.ajax({
			url:"/address/getAddressByUsername",
			type:"post",
			dataType:"json",
			async:false,
			success:function(result){
				if(result.code ==200){
					var addressVo=result.data;
					var div = "";
					$(addressVo).each(function (index,e) {
						div += "<tr>";
						div += "<td>"+e.contact+"</td>";
						div += "<td>"+e.provinceName+" "+e.cityName+" "+e.areName+" "+e.address+"</td>";
						var mob= e.mobile;
						div+="<td>"+mob.replace(mob.substring(4,9),"*****")+"</td>";
						div+="<td><a data-toggle='modal' data-target='.edit' onclick='toUpdate("+e.id+")'>编辑&nbsp;&nbsp;&nbsp;</a>";
						div += "<a href='javascript:deleteById("+e.id+")'>删除&nbsp;&nbsp;&nbsp;</a>默认地址</td>";
						div += "</tr>";
					})
					$("#tbodyid").html(div);
				}else {
					alert(result.message);
				}
			},
			error:function(){
				alert("系统异常，请联系管理员！");
			}
		});
	}


	//根据省查询市
	function getCitiesByProvinceid(pid) {
		$.ajax({
			url:"/address/getCitiesByProvinceid",
			data:{provinceid: pid},
			type:"post",
			dataType:"json",
			async:false,
			success:function(result){
				if(result.code == 200){
					var citiesList=result.data
					var div="<option value='"+ -1+"'>请选择</option>";
					$(citiesList).each(function (index,e) {
						div += "<option value='"+e.cityid+"'>"+e.city+"</option>";
					})
					$("#cityid").html(div);
					$("#townid").html("<option value='"+ -1+"'>请选择</option>");
				}else {
					alert(result.message);
				}
			},
			error:function(result){
				alert("系统异常，请联系管理员！");
			}
		});
	}


	//根据市查询县
	function getAreasByCityid(pid) {
		$.ajax({
			url: "/address/getAreasByCityid",
			data: {cityid: pid},
			type: "post",
			dataType: "json",
			async: false,
			success: function (result) {
				if (result.code == 200) {
					var areasList = result.data
					var div = "<option value='" + -1 + "'>请选择</option>";
					$(areasList).each(function (index, e) {
						div += "<option value='" + e.areaid + "'>" + e.area + "</option>";
					})
					$("#townid").html(div);
				} else {
					alert(result.message);
				}
			},
			error: function (result) {
				alert("系统异常，请联系管理员！");
			}
		});
	}

	//添加方法
	function addOrUpdate() {
		var id=$("#id").val();
		var provinceId=$("#provinceid").val();
		var cityId=$("#cityid").val();
		var townId=$("#townid").val();
		var mobile=$("#mobile").val();
		var address=$("#address").val();
		var contact=$("#contact").val();
		var alias=$("#alias").val();
		$.ajax({
			url:"/address/addOrUpdate",
			data:{id:id,provinceId: provinceId,cityId: cityId,townId: townId,mobile: mobile,address: address,contact: contact,alias: alias},
			type:"post",
			dataType:"json",
			async:false,
			success:function(result){
				if(result.code==200){
					alert(result.message);
				}else {
					alert(result.message);
				}
				window.location.reload();
			},
			error:function(result){
				alert("系统异常，请联系管理员！");
			}
		});
	}

	//回显
	function toUpdate(id) {
		$.ajax({
			url:"/address/toUpdate",
			data:{id:id},
			type:"post",
			dataType:"json",
			async:false,
			success:function(result){
				var data = result.data;
				$("#id").val(data.id);
				$("#provinceid").val(data.provinceId);
				$("#cityid").val(data.cityId);
				$("#townid").val(data.townId);
				$("#mobile").val(data.mobile);
				$("#address").val(data.address);
				$("#contact").val(data.contact);
				$("#alias").val(data.alias);
			},
			error:function(result){
				alert("系统异常，请联系管理员！");
			}
		});
	}


	//删除
	function deleteById(id) {
		$.ajax({
			url:"/address/deleteById",
			data:{id:id},
			type:"post",
			dataType:"json",
			async:false,
			success:function(result){
				alert(result.message);
				window.location.reload();
			},
			error:function(result){
				alert("系统异常，请联系管理员！");
			}
		});
	}

</script>
<script type="text/javascript" src="/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="/js/widget/nav.js"></script>
</body>
<!--header-->
<div id="account">
	<div class="py-container">
		<div class="yui3-g home">
			<!--左侧列表-->
			<div class="yui3-u-1-6 list">

				<div class="person-info">
					<div class="person-photo"><img src="/img/_/photo.png" alt=""></div>
					<div class="person-account">
						<span class="name">[[${username}]]</span>
						<span class="safe">账户安全</span>
					</div>
					<div class="clearfix"></div>
				</div>
				<div class="list-items">
					<dl>
						<dt><i>·</i> 订单中心</dt>
						<dd ><a href="home-index.html"   >我的订单</a></dd>
						<dd><a href="home-order-pay.html" >待付款</a></dd>
						<dd><a href="home-order-send.html"  >待发货</a></dd>
						<dd><a href="home-order-receive.html" >待收货</a></dd>
						<dd><a href="home-order-evaluate.html" >待评价</a></dd>
					</dl>
					<dl>
						<dt><i>·</i> 我的中心</dt>
						<dd><a href="home-person-collect.html" >我的收藏</a></dd>
						<dd><a href="home-person-footmark.html" >我的足迹</a></dd>
					</dl>
					<dl>
						<dt><i>·</i> 物流消息</dt>
					</dl>
					<dl>
						<dt><i>·</i> 设置</dt>
						<dd><a href="home-setting-info.html" >个人信息</a></dd>
						<dd><a href="home-setting-address.html" class="list-active" >地址管理</a></dd>
						<dd><a href="home-setting-safe.html" >安全管理</a></dd>
					</dl>
				</div>
			</div>
			<!--右侧主内容-->
			<div class="yui3-u-5-6">
				<div class="body userAddress">
					<div class="address-title">
						<span class="title">地址管理</span>
						<a data-toggle="modal" data-target=".edit" data-keyboard="false"   class="sui-btn  btn-info add-new">添加新地址</a>
						<span class="clearfix"></span>
					</div>
					<div class="address-detail">
						<table class="sui-table table-bordered">
							<thead>
							<tr>
								<th>姓名</th>
								<th>地址</th>
								<th>联系电话</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="tbodyid">
							<!--查询信息-->
							</tbody>
						</table>
					</div>


					<!--新增地址弹出层-->
					<div  tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade edit" style="width:580px;">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
									<h4 id="myModalLabel" class="modal-title">新增地址</h4>
								</div>
								<div class="modal-body">
									<form action="" class="sui-form form-horizontal">
										<input type="hidden" id="id">
										<div class="control-group">
											<label class="control-label">收货人：</label>
											<div class="controls">
												<input type="text" class="input-medium" id="contact">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">所在地区：</label>
											<div class="controls">
												<div data-toggle="distpicker">
													<div class="form-group area">
														<select class="form-control" id="provinceid" onchange="getCitiesByProvinceid(this.value)">
															<option value="-1">请选择</option>
															<option th:each="p : ${provincesList}" th:value="${p.provinceid}">[[${p.province}]]</option>
														</select>
													</div>
													<div class="form-group area">
														<select class="form-control" id="cityid" onchange="getAreasByCityid(this.value)">

														</select>
													</div>
													<div class="form-group area">
														<select class="form-control" id="townid">

														</select>
													</div>
												</div>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">详细地址：</label>
											<div class="controls">
												<input type="text" class="input-large" id="address">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">联系电话：</label>
											<div class="controls">
												<input type="text" class="input-medium" id="mobile">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">地址别名：</label>
											<div class="controls">
												<input type="text" class="input-medium" id="alias">
											</div>
											<div class="othername">
												建议填写常用地址：<a href="#" class="sui-btn btn-default">家里</a>　<a href="#" class="sui-btn btn-default">父母家</a>　<a href="#" class="sui-btn btn-default">公司</a>
											</div>
										</div>
									</form>
								</div>
								<div class="modal-footer">
									<button type="button" data-ok="modal" class="sui-btn btn-primary btn-large" onclick="addOrUpdate()">确定</button>
									<button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">取消</button>
								</div>
							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div>
</div>
<!-- 底部栏位 -->
<!--页面底部-->
<div class="clearfix footer">
	<!--引入底部-->
	<div th:insert="/admin/common/dibu.html"></div>
</div>
<!--页面底部END-->
undefined

</html>